﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using csvm2.message.contract;
using csvm2.pin.contract;

namespace csvm2.portal
{
    public partial class WinMain : Form, IPortal
    {
        public WinMain()
        {
            InitializeComponent();
        }


        private void ladenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.OnLoad("filename.txt - " + DateTime.Now);
        }


        public void ProcessHeader(Record header)
        {
            this.listBox1.Items.Clear();
            DisplayRecord(header);
            this.listBox1.Items.Add("---");
        }

        private void DisplayRecord(Record rec)
        {
            string item = rec.Values.Aggregate("", (current, v) => current + (v + ","));
            this.listBox1.Items.Add(item);
        }

        public void ProcessPage(Page page)
        {
            foreach (var rec in page.Records)
                DisplayRecord(rec);
        }

        public void ProcessProgress(double progress)
        {
            this.toolStripProgressBar1.Value = (int)progress;
        }


        public event Action<string> OnLoad;
    }
}
